//二级菜单
$(".nav-list>li").mouseenter(function(){
	$(this).children("ul").stop().show();
}).mouseleave(function(){
	$(this).children("ul").stop().hide();
});

//顶部悬浮

$(function(){
	$(window).scroll(function(){
		var st = $(document).scrollTop();
		if(128<st){
			$("#nav").addClass("retract");
		}else{
			$("#nav").removeClass("retract");
		}
		
	});
	
	$(".nav-search p input").focus(function(){
		$(".nav-search ul").css("display","block");
	}).blur(function(){
		$(".nav-search ul").css("display","none");
	})
	
})
//回到顶部
function Float(elem, tip){
	var that = this;
	this.tip = tip;
	// TOP的点击事件
	tip.click( this.top_click );
	// 当手动拖动滚动条时
	$(window).scroll( function(){
		that.win_scroll();
	} );
}
Float.prototype.top_click = function(){
	$("html,body").animate({"scrollTop":0}, 500);
}
Float.prototype.win_scroll = function(){
	var st = $(document).scrollTop();
	if(0<st){
			this.tip.fadeIn();
		}else{
			this.tip.fadeOut();
		}
}
var f = new Float($("html,body"), $(".rightBar-top"));


//获取商品

$(function(){
	$.ajax({
		type:"GET",
		url:"../json/list.json",
		success:function(d){
			//console.log(d)
			var _html1="";
			for(var key in d["list1"]){
				
				_html1+='<li><a href="detail.html?pid='+d["list1"][key]["id"]+'" target="_blank"><i><img src="'+d["list1"][key]["img"]+'"/></i> '
				if(d["list1"][key]["news"]){
					_html1 += '<b>'+d["list1"][key]["news"]+'</b>'
				}
				_html1 += '<dl><dt>'+d["list1"][key]["title"]+'</dt><dd>￥'+d["list1"][key]["price"]+'</dd></dl></a></li>';
			}
			$(".list1").html(_html1);
			
			var _html2="";
			for(var key in d["list2"]){
				
				_html2+='<li><a href="#"><i><img src="'+d["list2"][key]["img"]+'"/></i> '
				if(d["list2"][key]["news"]){
					_html2 += '<b>'+d["list2"][key]["news"]+'</b>'
				}
				_html2 += '<dl><dt>'+d["list2"][key]["title"]+'</dt><dd>'+d["list2"][key]["price"]+'</dd></dl></a></li>';
			}
			$(".list2").html(_html2);
			
			var _html3="";
			for(var key in d["list3"]){
				
				_html3+='<li><a href="#"><i><img src="'+d["list3"][key]["img"]+'"/></i> '
				if(d["list3"][key]["news"]){
					_html3 += '<b>'+d["list3"][key]["news"]+'</b>'
				}
				_html3 += '<dl><dt>'+d["list3"][key]["title"]+'</dt><dd>'+d["list3"][key]["price"]+'</dd></dl></a></li>';
			}
			$(".list3").html(_html3);
			//图片放大

			$(".category a").mouseover(function(){				
				$(this).find("img").stop().animate({
					"width":260,
					"height":260,
					"left":-5,
					"top":-5
				})
			}).mouseout(function(){
				$(this).find("img").stop().animate({
					"width":255,
					"height":255,
					"left":0,
					"top":0
				})
			});
		}
	})
})


